package com.example.alibabanacosdiscoveryserver.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @createBy guoqiang
 * @createTime 2019/4/3
 * @describe
 */
@RequestMapping("/server")
@RestController
@Tag(name="服务注册中心")
public class ProviderController {
    @RequestMapping(value = "/test",method = RequestMethod.GET)
    @Operation(summary ="服务提供-测试接口是否通")
    public String test(@RequestParam String name){
        char[] charArray = name.toCharArray();
        return  "hello,我是服务端的接口，接口是通的，参数是： "+name;
    }

    public static void main(String[] args) {
        thirdMax(new int[]{3, 2, 1});
    }
    public static int thirdMax(int[] nums) {
        if(nums.length==1) return nums[0];
        if(nums.length==2) return nums[0]>nums[1]?nums[0]:nums[1];
        int index=0;
        //双指针
        int l=0;
        int r=0;
        //先desc排序
        List list=new ArrayList();
        Arrays.sort(list.toArray());
        while(r<nums.length){
            if(nums[r]>nums[l]){
                int tmp=nums[l];
                nums[l]=nums[r];
                nums[r]=tmp;
                l++;
            }
            r++;
        }
        int res=0;
        Set<Integer> set=new HashSet<Integer>();
        for(int i=0;i<nums.length;i++){
            set.add(nums[i]);
        }
        return  new LinkedList<Integer>(set).get(2);
    }
    public static int getIndex(int[] score,int o){
        for(int i=3;i<score.length;i++){
            if(score[i]==o){
                return i+1;
            }
        }
        return -1;
    }
    public static void sortArray(int[] score){
        int len=score.length;
        for(int i=0;i<len-1;i++){
            for(int j=0;j<len-i-1;j++){
                if(score[j]<score[j+1]){
                    int tmp=score[j];
                    score[j]=score[j+1];
                    score[j+1]=tmp;
                }

            }
        }
    }

    /****@SentinelResource 注解用来标识资源是否被限流、降级，如果不加该注解服务也会在sentinel中监控到****/
    @SentinelResource(value = "hello")
    @GetMapping("/hello")
    @Operation(summary = "服务提供-测试SentinelHello的限流降级")
    public String hello(@RequestParam String name){
        return  "我是服务端接口，测试@SentinelResource的接口的限流和降级，参数是："+name;
    }

}
